package dom2;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

public class ParseVOSXml {

	public static void main(String argv[]) {

		parseXML();
	}

	public static void parseXML() {
		try {

			File fXmlFile = new File("C:\\Users\\lin\\Desktop\\WebExport\\20130312_Kino_135909.xml");

			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse(fXmlFile);
			
			Element rootElement = doc.getDocumentElement();

			// optional, but recommended
			// read this -
			// http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
			rootElement.normalize();

			System.out.println("Root element :" + rootElement.getNodeName());

			NodeList nList = doc.getElementsByTagName("VOS");

			System.out.println("----------------------------");

			for (int temp = 0; temp < nList.getLength(); temp++) {

				Node nNode = nList.item(temp);

				System.out.println("\nCurrent Element :" + nNode.getNodeName());

				if (nNode.getNodeType() == Node.ELEMENT_NODE) {

					Element eElement = (Element) nNode;


					System.out.println("TVSTATION : " + eElement.getElementsByTagName("TVSTATION").item(0).getTextContent());
					System.out.println("TITLE : " + eElement.getElementsByTagName("TITLE").item(0).getTextContent());
					System.out.println("SHOWNAME : " + eElement.getElementsByTagName("SHOWNAME").item(0).getTextContent());
					System.out.println("DESCRIPTION : " + eElement.getElementsByTagName("DESCRIPTION").item(0).getTextContent());
					System.out.println("DURATION : " + eElement.getElementsByTagName("DURATION").item(0).getTextContent());
					System.out.println("TIMEBASE : " + eElement.getElementsByTagName("TIMEBASE").item(0).getTextContent());
					System.out.println("ID : " + eElement.getElementsByTagName("ID").item(0).getTextContent());
					System.out.println("RUNDOWN : " + eElement.getElementsByTagName("RUNDOWN").item(0).getTextContent());
					System.out.println("RUNDOWNDATA : " + eElement.getElementsByTagName("RUNDOWNDATE").item(0).getTextContent());
					System.out.println("LANGUAGE : " + eElement.getElementsByTagName("LANGUAGE").item(0).getTextContent());
					System.out.println("TRANSMISSIONDATE : " + eElement.getElementsByTagName("TRANSMISSIONDATE").item(0).getTextContent());
					System.out.println("CREATIONDATE : " + eElement.getElementsByTagName("CREATIONDATE").item(0).getTextContent());
					System.out.println("EXPORTDATE : " + eElement.getElementsByTagName("EXPORTDATE").item(0).getTextContent());

				}
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}